//
//  LXVisitorView.swift
//  weibo
//
//  Created by 罗心 on 16/6/25.
//  Copyright © 2016年 罗心. All rights reserved.
//

import UIKit
import SnapKit

class LXVisitorView: UIView {
    //button点击闭包
    var closure:(()->())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //MARK: -设置视图
    private func setupUI() {
        backgroundColor = RGB(237, green: 237, blue: 237)
    
    //添加控件
        addSubview(feedImageView)
        addSubview(maskImageView)
        addSubview(iconImageview)
        addSubview(messageLable)
        addSubview(loginButton)
        addSubview(registerButton)
        
        
        
    //设置约束
        feedImageView.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        
        maskImageView.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        
        iconImageview.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        messageLable.snp_makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 224, height: 36))
//            make.size.equalTo(CGSize(width: 100, height: 36))
            make.top.equalTo(maskImageView.snp_bottom).offset(16)
            make.centerX.equalTo(maskImageView)
        }
        loginButton.snp_makeConstraints { (make) in
            make.size.equalTo(CGSizeMake(100, 36))
            make.leading.equalTo(messageLable)
            make.top.equalTo(messageLable.snp_bottom).offset(16)
        }
        registerButton.snp_makeConstraints { (make) in
            make.size.equalTo(CGSizeMake(100, 36))
            make.trailing.equalTo(messageLable)
            make.top.equalTo(loginButton)
            
        }
    
    
    }
    
    //MARK: 设置动画
    
    func setAmination(){
        let amination = CABasicAnimation(keyPath: "transform.rotation")
        amination.duration = 10
        amination.toValue = M_PI * 2
        amination.repeatCount = MAXFLOAT
        amination.removedOnCompletion = false
        feedImageView.layer.addAnimation(amination, forKey: nil)
    }
    

    
    func setupVisitorViewInfo(imageName:String?, title:String?){
        if let img = imageName, let tit = title{
            iconImageview.image = UIImage(named: img)
            messageLable.text = tit
            feedImageView.hidden = true
        } else {
            setAmination()
        }
        
    }
    
    //MARK: -懒加载控件
    //圆圈
   private lazy var feedImageView:UIImageView = UIImageView(image:UIImage(named:"visitordiscover_feed_image_smallicon"))
    
    //遮罩
    private lazy var maskImageView:UIImageView = UIImageView(image:UIImage(named:"visitordiscover_feed_mask_smallicon"))
    
    //房子
    private lazy var iconImageview:UIImageView = UIImageView(image:UIImage(named:"visitordiscover_feed_image_house"))
    //文字
    private lazy var messageLable:UILabel = {
        let label = UILabel()
        label.text = "关注一些人，回这里看看有什么惊喜"
        label.textColor = ThemeColor
        label.font = UIFont.systemFontOfSize(14)
        label.textAlignment = .Center
        
        return label
    }()
    
    //按钮点击事件
    @objc private func buttonClick(){
        closure?()
    }
    
    //按钮(登录\注册)
    
    private lazy var loginButton:UIButton = {
        let button = UIButton()
        button.addTarget(self, action: #selector(LXVisitorView.buttonClick), forControlEvents: UIControlEvents.TouchUpInside)
        button.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: UIControlState.Normal)
        button.setTitle("登录", forState: UIControlState.Normal)
        button.setTitleColor(ThemeColor, forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        return button
    }()
    
    private lazy var registerButton:UIButton = {
       let button = UIButton()
        button.addTarget(self, action: #selector(LXVisitorView.buttonClick), forControlEvents: UIControlEvents.TouchUpInside)
        button.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: UIControlState.Normal)
        button.setTitle("注册", forState: UIControlState.Normal)
        button.setTitleColor(ThemeColor, forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        return button
    }()
    
    
    
    
    
    
    
    
    
    
    
    

}
